<?php

/**
 * Pozo filter form base class.
 *
 * @package    prode
 * @subpackage filter
 * @author     Your name here
 */
abstract class BasePozoFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'anho'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'torneo_id'             => new sfWidgetFormPropelChoice(array('model' => 'Torneo', 'add_empty' => true)),
      'temporada_id'          => new sfWidgetFormPropelChoice(array('model' => 'Temporada', 'add_empty' => true)),
      'fechanro'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'habilitado'            => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'montoinicial'          => new sfWidgetFormFilterInput(),
      'totalpagado'           => new sfWidgetFormFilterInput(),
      'montofinal'            => new sfWidgetFormFilterInput(),
      'created_at'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'detalleganadores_list' => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => true)),
      'detallepozo_list'      => new sfWidgetFormPropelChoice(array('model' => 'Apuesta', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'anho'                  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'torneo_id'             => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Torneo', 'column' => 'id')),
      'temporada_id'          => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Temporada', 'column' => 'id')),
      'fechanro'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'habilitado'            => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'montoinicial'          => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'totalpagado'           => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'montofinal'            => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'created_at'            => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'detalleganadores_list' => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'required' => false)),
      'detallepozo_list'      => new sfValidatorPropelChoice(array('model' => 'Apuesta', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('pozo_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addDetalleganadoresListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(DetalleganadoresPeer::POZO_ID, PozoPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(DetalleganadoresPeer::SF_GUARD_USER, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(DetalleganadoresPeer::SF_GUARD_USER, $value));
    }

    $criteria->add($criterion);
  }

  public function addDetallepozoListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(DetallepozoPeer::POZO_ID, PozoPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(DetallepozoPeer::APUESTA_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(DetallepozoPeer::APUESTA_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Pozo';
  }

  public function getFields()
  {
    return array(
      'id'                    => 'Number',
      'anho'                  => 'Number',
      'torneo_id'             => 'ForeignKey',
      'temporada_id'          => 'ForeignKey',
      'fechanro'              => 'Number',
      'habilitado'            => 'Boolean',
      'montoinicial'          => 'Number',
      'totalpagado'           => 'Number',
      'montofinal'            => 'Number',
      'created_at'            => 'Date',
      'detalleganadores_list' => 'ManyKey',
      'detallepozo_list'      => 'ManyKey',
    );
  }
}
